/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean;

import dao.MateriaPrimaDao;
import dao.impl.MateriaDaoImpl;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import model.Materiaprima;

/**
 *
 * @author Joel
 */
@ManagedBean(name="materiaPrimaBean")
@SessionScoped
public class materiaPrimaBean {
private Materiaprima mate;
private List<Materiaprima> mates;
    /**
     * Creates a new instance of materiaPrimaBean
     */
    public materiaPrimaBean() {
        mate = new Materiaprima();
    }

    public Materiaprima getMate() {
        return mate;
    }

    public void setMate(Materiaprima mate) {
        this.mate = mate;
    }

    public List<Materiaprima> getMates() {
        MateriaPrimaDao obj = new MateriaDaoImpl();
        mates = obj.buscarTodos();
        return mates;
    }
     public void insertar(){
        MateriaPrimaDao obj = new MateriaDaoImpl();
        obj.insertar(mate);
        mate = new Materiaprima();
    }
     public void prepararActualizar(Integer id) {
         MateriaPrimaDao obj = new MateriaDaoImpl();
         mate = obj.buscarporId(id); 
    }
    public void actualizar()
    {
        MateriaPrimaDao obj = new MateriaDaoImpl();
        obj.actualizar(mate);
        mate = new Materiaprima();
    }
    
    public void eliminar()
    {
       MateriaPrimaDao obj = new MateriaDaoImpl();
        obj.eliminar(mate);
        mate = new Materiaprima();
    }
    
}
